/*
 Graphical View of DocRecord
 */

package GraphsWindowPackage.DocRecordPackage;

/**
 * @author quang
 */

import javafx.scene.Node;

import javafx.scene.paint.Color;
import javafx.scene.layout.HBox;
import javafx.scene.Group;
import javafx.util.Math;
import javafx.scene.shape.Rectangle;
import GraphsWindowPackage.EntryView;

/**
 * @author quang
 */


public class DocRecordView extends EntryView {
    function createShapes(documents: Document[]) {
        if (documents.isEmpty()) return null;

        var shapes: Node[];        
        for (i in [0..sizeof documents - 1]) {
            insert DocumentView {
                x: (documents[i].time - startShownTime) * this.numPixPerTimeUnit;
                y: this.circleRadius
                viewHeight: timeLineStrokeWidth
                time: "{Math.round(Math.floor(documents[i].time))} days {Math.round ((documents[i].time - Math.floor(documents[i].time)) * 24)} hours from the beginning of treatment period"
                info: "{documents[i].text}"
            } into shapes;
        }
        return shapes;
    }

    public override function create(): Node {
        var docRecord = bind (entry as DocRecord).createEntryInTimeRange(startShownTime, endShownTime);
        def bgRect = Rectangle {
            x: 0
            y: 0
            width: timeLineWidth, height: timeLineStrokeWidth
            fill: Color.WHITE
            stroke: Color.GRAY
            smooth: false
        }

        var shapes = bind createShapes(docRecord.documents);
        return HBox {
            content: bind if (shown) [nameField, Group { content: bind [bgRect, shapes] }]
                        else []
        }
    }
}
